<?php
/**
 * Created by PhpStorm.
 * User: wudiying
 * Date: 2020/2/18
 * Time: 上午12:26
 */

/**
 *swoole之tcp异步客户端
 *
 * new swoole_client()
 * SWOOLE_SOCK_TCP //TCP协议
 * SWOOLE_SOCK_ASYNC //异步支持
 *
 */


//示例：
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
//注册连接成功的回调
$client->on('connect', function ($cli) {
    $cli->send('hello');
});

//注册数据接收
$client->on('receive', function ($cli, $data) {
    echo $data;
});

//注册连接失败
$client->on('error', function ($cli) {
    echo '失败';
});

//注册关闭
$client->on('close', function ($cli) {
    echo '关闭';
});

//发起连接
$client->connect('xxx.xxx.xxx.xxx', 9501, 10);